﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using DBService;
using YArchitech.Revit;
using YArchitech.Revit.RevitExtension;
using YJKArch.ImportStructureProject.ImportObjects;
using YJKArch.Utils;

namespace YJKArch.ImportStructureProject
{
	internal class Importer
	{
		public Importer(ExternalCommandData cmdData)
		{
			this.m_Revit = cmdData;
		}

		public Result ImportFromXMLFile(string fileName, ref string message)
		{
			string text = this.m_Revit.Application.ActiveUIDocument.Document.PathName;
			if (text.CompareTo("") != 0)
			{
				int length = text.LastIndexOf("\\");
				text = text.Substring(0, length);
			}
			if (!this.ReadStructureInfo(fileName, ref message))
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			return this.Import(ref message);
		}

		public Result ImportFromDatabase(ref string message)
		{
			if (!this.ReadStructureInfoFromDbService(ref message))
			{
				return Autodesk.Revit.UI.Result.Failed;
			}
			return this.Import(ref message);
		}

		private Result Import(ref string message)
		{
			ElementId defaultRectangeBeamFamilyId = null;
			ElementId defaultRectangeColumnFamilyId = null;
			ElementId defaultCircleColumnFamilyId = null;
			ElementId elementId = null;
			ElementId elementId2 = null;
			if (!this.SetImportOption(ref defaultRectangeBeamFamilyId, ref defaultRectangeColumnFamilyId, ref defaultCircleColumnFamilyId, ref elementId, ref elementId2))
			{
				return Autodesk.Revit.UI.Result.Cancelled;
			}
			if (this.SetSectionMapping(defaultRectangeBeamFamilyId, defaultRectangeColumnFamilyId, defaultCircleColumnFamilyId) != null)
			{
				return Autodesk.Revit.UI.Result.Cancelled;
			}
			DialogResult dialogResult = MessageBox.Show("导入结构数据后原图中部分建筑数据将会被替换，是否另存？", "盈建科提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk, MessageBoxDefaultButton.Button1);
			if (DialogResult.Yes == dialogResult)
			{
				SaveFileDialog saveFileDialog = new SaveFileDialog();
				saveFileDialog.Filter = "Revit文件|*.rvt";
				saveFileDialog.RestoreDirectory = true;
				saveFileDialog.FilterIndex = 1;
				if (saveFileDialog.ShowDialog() == DialogResult.OK)
				{
					string fileName = saveFileDialog.FileName;
					SaveAsOptions saveAsOptions = new SaveAsOptions();
					saveAsOptions.OverwriteExistingFile = true;
					RevitVersionFuncs.SaveAs(this.m_Revit.Application.ActiveUIDocument.Document, fileName, saveAsOptions);
				}
			}
			this.GetLevelList();
			Transaction transaction = null;
			transaction = new Transaction(this.m_Revit.Application.ActiveUIDocument.Document);
			transaction.Start("import structure prject");
			try
			{
				if (this.ImportData(ref message) != null)
				{
					if (transaction != null && transaction.HasStarted() && !transaction.HasEnded())
					{
						transaction.RollBack();
					}
					return Autodesk.Revit.UI.Result.Cancelled;
				}
				this.EreaseOldElements();
				transaction.Commit();
			}
			catch (Exception ex)
			{
				message = ex.Message;
				if (transaction != null && transaction.HasStarted() && !transaction.HasEnded())
				{
					transaction.RollBack();
				}
				return Autodesk.Revit.UI.Result.Failed;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private Result ImportData(ref string message)
		{
			List<KeyValuePair<int, string>> list = new List<KeyValuePair<int, string>>();
			int num = 0;
			if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_BEAM) != ImportComponentStyleOption.ICS_NULL)
			{
				KeyValuePair<int, string> item = new KeyValuePair<int, string>(this.m_BeamStructureData.Count, "梁");
				list.Add(item);
				num += item.Key;
			}
			if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_COLUMN) != ImportComponentStyleOption.ICS_NULL)
			{
				KeyValuePair<int, string> item2 = new KeyValuePair<int, string>(this.m_ColumnStructureData.Count, "柱");
				list.Add(item2);
				num += item2.Key;
			}
			if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_WALL) != ImportComponentStyleOption.ICS_NULL)
			{
				KeyValuePair<int, string> item3 = new KeyValuePair<int, string>(this.m_WallStructureData.Count, "墙");
				list.Add(item3);
				num += item3.Key;
			}
			if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_FLOOR) != ImportComponentStyleOption.ICS_NULL)
			{
				KeyValuePair<int, string> item4 = new KeyValuePair<int, string>(this.m_FloorStructureData.Count, "楼板");
				list.Add(item4);
				num += item4.Key;
			}
			MyProgressBar myProgressBar = new MyProgressBar(list, "导入结构数据", true);
			try
			{
				if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_BEAM) != ImportComponentStyleOption.ICS_NULL && !this.ImportBeam(ref myProgressBar))
				{
					myProgressBar.Dispose();
					return Autodesk.Revit.UI.Result.Failed;
				}
				if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_COLUMN) != ImportComponentStyleOption.ICS_NULL && !this.ImportColumn(ref myProgressBar))
				{
					myProgressBar.Dispose();
					return Autodesk.Revit.UI.Result.Failed;
				}
				if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_WALL) != ImportComponentStyleOption.ICS_NULL && !this.ImportWall(ref myProgressBar))
				{
					myProgressBar.Dispose();
					return Autodesk.Revit.UI.Result.Failed;
				}
				if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_FLOOR) != ImportComponentStyleOption.ICS_NULL && !this.ImportFloor(ref myProgressBar))
				{
					myProgressBar.Dispose();
					return Autodesk.Revit.UI.Result.Failed;
				}
			}
			catch (Exception ex)
			{
				message = ex.Message;
				if (myProgressBar != null)
				{
					myProgressBar.Dispose();
				}
				return Autodesk.Revit.UI.Result.Failed;
			}
			myProgressBar.Dispose();
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private bool SetImportOption(ref ElementId defaultRectangeBeamFamilyId, ref ElementId defaultRectangeColumnFamilyId, ref ElementId defaultCircleColumnFamilyId, ref ElementId defaultWallTypeId, ref ElementId defaultFloorTypeId)
		{
			List<Element> wallTypeList = new List<Element>();
			List<Element> floorTypeList = new List<Element>();
			List<Element> rectColumnSymbolList = new List<Element>();
			List<Element> circleColumnSymbolList = new List<Element>();
			List<Element> rectBeamSymbolList = new List<Element>();
			this.GetDefaultComponentTypeList(ref wallTypeList, ref floorTypeList, ref rectColumnSymbolList, ref circleColumnSymbolList, ref rectBeamSymbolList);
			bool flag = this.IsImportedWithBeam();
			bool flag2 = this.IsImportedWithColumn();
			bool flag3 = this.IsImportedWithWall();
			bool flag4 = this.IsImportedWithFloor();
			if (flag && flag2 && flag3 && flag4)
			{
				MessageBox.Show("当前工程已经完成过导入，不能重复导入！", "盈建科提示");
				return false;
			}
			int importRectBeam = 0;
			int importRectColumnCount = 0;
			int importCircleCount = 0;
			int importWallCount = 0;
			int importFloorCount = 0;
			if (!flag)
			{
				importRectBeam = this.GetImportRectangleBeamCount();
			}
			if (!flag2)
			{
				importRectColumnCount = this.GetImportRectangleColumnCount();
				importCircleCount = this.GetImportCircleColumnCount();
			}
			if (!flag3)
			{
				importWallCount = this.GetImportWallCount();
			}
			if (!flag4)
			{
				importFloorCount = this.GetImportFloorCount();
			}
			ImportOptionForm importOptionForm = new ImportOptionForm(importWallCount, wallTypeList, importFloorCount, floorTypeList, importRectColumnCount, rectColumnSymbolList, importCircleCount, circleColumnSymbolList, importRectBeam, rectBeamSymbolList);
			if (importOptionForm.ShowDialog() != DialogResult.OK)
			{
				return false;
			}
			ImportComponentStyleOption importComponentStyleOption = ImportComponentStyleOption.ICS_NULL;
			if (importOptionForm.ImportBeam && !flag)
			{
				importComponentStyleOption |= ImportComponentStyleOption.ICS_BEAM;
			}
			if (importOptionForm.ImportColumn && !flag2)
			{
				importComponentStyleOption |= ImportComponentStyleOption.ICS_COLUMN;
			}
			if (importOptionForm.ImportWall && !flag3)
			{
				importComponentStyleOption |= ImportComponentStyleOption.ICS_WALL;
			}
			if (importOptionForm.ImportFloor && !flag4)
			{
				importComponentStyleOption |= ImportComponentStyleOption.ICS_FLOOR;
			}
			if (importComponentStyleOption == ImportComponentStyleOption.ICS_NULL)
			{
				return false;
			}
			defaultRectangeBeamFamilyId = importOptionForm.DefaultRectangeBeamFamilyId;
			defaultRectangeColumnFamilyId = importOptionForm.DefaultRectangeColumnFamilyId;
			defaultCircleColumnFamilyId = importOptionForm.DefaultCircleColumnFamilyId;
			defaultWallTypeId = importOptionForm.DefaultWallTypeId;
			defaultFloorTypeId = importOptionForm.DefaultFloorTypeId;
			this.m_ImportOption = new ImportOptions(importComponentStyleOption, defaultRectangeBeamFamilyId, defaultRectangeColumnFamilyId, defaultCircleColumnFamilyId, defaultWallTypeId, defaultFloorTypeId);
			return true;
		}

		private Result SetSectionMapping(ElementId defaultRectangeBeamFamilyId, ElementId defaultRectangeColumnFamilyId, ElementId defaultCircleColumnFamilyId)
		{
			if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_BEAM) == ImportComponentStyleOption.ICS_NULL && (this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_COLUMN) == ImportComponentStyleOption.ICS_NULL)
			{
				return Autodesk.Revit.UI.Result.Succeeded;
			}
			List<Element> list = new List<Element>();
			if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_BEAM) != ImportComponentStyleOption.ICS_NULL)
			{
				this.GetImportArchitectureBeamTypeList(ref list);
				if (this.GetImportRectangleBeamCount() > 0)
				{
					Element defaultRectangeBeamFamily = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, defaultRectangeBeamFamilyId);
					if (list.FindIndex((Element s) => s.Id == defaultRectangeBeamFamily.Id) < 0)
					{
						list.Add(defaultRectangeBeamFamily);
					}
				}
			}
			List<Element> list2 = new List<Element>();
			List<Element> list3 = new List<Element>();
			if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_COLUMN) != ImportComponentStyleOption.ICS_NULL)
			{
				this.GetImportArchitectureColumnTypeList(ref list2, ref list3);
				if (this.GetImportRectangleColumnCount() > 0)
				{
					Element defaultRectangeColumnFamily = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, defaultRectangeColumnFamilyId);
					if (list2.FindIndex((Element s) => s.Id == defaultRectangeColumnFamily.Id) < 0)
					{
						list2.Add(defaultRectangeColumnFamily);
					}
				}
				if (this.GetImportCircleColumnCount() > 0)
				{
					Element defaultCircleColumnFamily = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, defaultCircleColumnFamilyId);
					if (list3.FindIndex((Element s) => s.Id == defaultCircleColumnFamily.Id) < 0)
					{
						list3.Add(defaultCircleColumnFamily);
					}
				}
			}
			if (!this.SetSectionSizePropertiesMapping(list, list2, list3))
			{
				return Autodesk.Revit.UI.Result.Cancelled;
			}
			return Autodesk.Revit.UI.Result.Succeeded;
		}

		private void GetImportArchitectureBeamTypeList(ref List<Element> importArchitectureRectBeamFamilyList)
		{
			foreach (BeamInfos beamInfos in this.m_BeamStructureData)
			{
				ElementId oldElementId = beamInfos.OldElementId;
				if (!(null == oldElementId))
				{
					FamilyInstance familyInstance = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, oldElementId) as FamilyInstance;
					if (familyInstance != null)
					{
						FamilySymbol symbol = familyInstance.Symbol;
						Family family = symbol.Family;
						if (beamInfos.SectionStyle == PoleSectionStyle.CSS_RECTANG && importArchitectureRectBeamFamilyList.FindIndex((Element s) => s.Id == family.Id) < 0)
						{
							importArchitectureRectBeamFamilyList.Add(family);
						}
					}
				}
			}
		}

		private void GetImportArchitectureColumnTypeList(ref List<Element> importArchitectureRectColumnFamilyList, ref List<Element> importArchitectureCircleColumnFamilyList)
		{
			foreach (ColumnInfos columnInfos in this.m_ColumnStructureData)
			{
				ElementId oldElementId = columnInfos.OldElementId;
				if (!(null == oldElementId))
				{
					FamilyInstance familyInstance = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, oldElementId) as FamilyInstance;
					if (familyInstance != null)
					{
						FamilySymbol symbol = familyInstance.Symbol;
						Family family = symbol.Family;
						if (columnInfos.SectionStyle == PoleSectionStyle.CSS_RECTANG)
						{
							if (importArchitectureRectColumnFamilyList.FindIndex((Element s) => s.Id == family.Id) < 0)
							{
								importArchitectureRectColumnFamilyList.Add(family);
							}
						}
						else if (columnInfos.SectionStyle == PoleSectionStyle.CSS_CIRCLE && importArchitectureCircleColumnFamilyList.FindIndex((Element s) => s.Id == family.Id) < 0)
						{
							importArchitectureCircleColumnFamilyList.Add(family);
						}
					}
				}
			}
		}

		private int GetImportWallCount()
		{
			return this.m_WallStructureData.Count;
		}

		private int GetImportFloorCount()
		{
			return this.m_FloorStructureData.Count;
		}

		private int GetImportRectangleBeamCount()
		{
			int num = 0;
			using (List<BeamInfos>.Enumerator enumerator = this.m_BeamStructureData.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					if (enumerator.Current.SectionStyle == PoleSectionStyle.CSS_RECTANG)
					{
						num++;
					}
				}
			}
			return num;
		}

		private int GetImportRectangleColumnCount()
		{
			int num = 0;
			using (List<ColumnInfos>.Enumerator enumerator = this.m_ColumnStructureData.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					if (enumerator.Current.SectionStyle == PoleSectionStyle.CSS_RECTANG)
					{
						num++;
					}
				}
			}
			return num;
		}

		private int GetImportCircleColumnCount()
		{
			int num = 0;
			using (List<ColumnInfos>.Enumerator enumerator = this.m_ColumnStructureData.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					if (enumerator.Current.SectionStyle == PoleSectionStyle.CSS_CIRCLE)
					{
						num++;
					}
				}
			}
			return num;
		}

		private void GetDefaultComponentTypeList(ref List<Element> wallTypeList, ref List<Element> floorTypeList, ref List<Element> rectColumnFamilyList, ref List<Element> circleColumnFamilyList, ref List<Element> rectBeamFamilyList)
		{
			foreach (Element element in new FilteredElementCollector(this.m_Revit.Application.ActiveUIDocument.Document).OfClass(typeof(Family)).ToElements())
			{
				Family family = element as Family;
				if (family != null)
				{
					Category familyCategory = RevitVersionFuncs.GetFamilyCategory(family);
					if (familyCategory != null && -2001330 == familyCategory.Id.IntegerValue)
					{
						List<FamilySymbol> symbols = family.GetSymbols();
						if (symbols.Count != 0)
						{
							Element element2 = symbols[0];
							int num = 0;
							foreach (object obj in element2.Parameters)
							{
								Parameter parameter = (Parameter)obj;
								if ((int)parameter.StorageType == 2 && parameter.AsDouble() > 0.0)
								{
									num++;
								}
							}
							if (num > 1)
							{
								rectColumnFamilyList.Add(family);
								circleColumnFamilyList.Add(family);
							}
						}
					}
				}
			}
			foreach (Element element3 in new FilteredElementCollector(this.m_Revit.Application.ActiveUIDocument.Document).OfClass(typeof(Family)).ToElements())
			{
				Family family2 = element3 as Family;
				if (family2 != null)
				{
					Category familyCategory2 = RevitVersionFuncs.GetFamilyCategory(family2);
					if (familyCategory2 != null && -2001320 == familyCategory2.Id.IntegerValue)
					{
						List<FamilySymbol> symbols2 = family2.GetSymbols();
						if (symbols2.Count != 0)
						{
							Element element4 = symbols2[0];
							int num2 = 0;
							foreach (object obj2 in element4.Parameters)
							{
								Parameter parameter2 = (Parameter)obj2;
								if ((int)parameter2.StorageType == 2 && parameter2.AsDouble() > 0.0)
								{
									num2++;
								}
							}
							if (num2 > 1)
							{
								rectBeamFamilyList.Add(family2);
							}
						}
					}
				}
			}
			foreach (Element element5 in new FilteredElementCollector(this.m_Revit.Application.ActiveUIDocument.Document).OfClass(typeof(WallType)).ToElements())
			{
				WallType wallType = element5 as WallType;
				if (wallType != null)
				{
					CompoundStructure compoundStructure = wallType.GetCompoundStructure();
					if (compoundStructure != null)
					{
						IEnumerator<CompoundStructureLayer> enumerator3 = compoundStructure.GetLayers().GetEnumerator();
						{
							while (enumerator3.MoveNext())
							{
								if ((int)enumerator3.Current.Function == 1)
								{
									wallTypeList.Add(wallType);
									break;
								}
							}
						}
					}
				}
			}
			foreach (Element element6 in new FilteredElementCollector(this.m_Revit.Application.ActiveUIDocument.Document).OfClass(typeof(FloorType)).ToElements())
			{
				Category category = element6.Category;
				if (category != null && -2000032 == category.Id.IntegerValue)
				{
					FloorType floorType = element6 as FloorType;
					if (floorType != null)
					{
						CompoundStructure compoundStructure2 = floorType.GetCompoundStructure();
						if (compoundStructure2 != null)
						{
							IEnumerator<CompoundStructureLayer> enumerator3 = compoundStructure2.GetLayers().GetEnumerator();
							{
								while (enumerator3.MoveNext())
								{
									if ((int)enumerator3.Current.Function == 1)
									{
										floorTypeList.Add(floorType);
										break;
									}
								}
							}
						}
					}
				}
			}
		}

		private void GetLevelList()
		{
			foreach (Element element in new FilteredElementCollector(this.m_Revit.Application.ActiveUIDocument.Document).OfClass(typeof(Level)).ToElements())
			{
				Level level = element as Level;
				if (level != null)
				{
					this.m_AllLevels.Add(level);
				}
			}
		}

		private bool ReadStructureInfo(string structureInfoFilePath, ref string errMessage)
		{
			return new ReadStructureXMLFile(ref this.m_OldColumnsId, ref this.m_OldBeamsId, ref this.m_OldWallsId, ref this.m_OldFloorsId, ref this.m_BeamStructureData, ref this.m_ColumnStructureData, ref this.m_WallStructureData, ref this.m_FloorStructureData).ReadStructureInfo(structureInfoFilePath, ref errMessage);
		}

		private bool ReadStructureInfoFromDbService(ref string errMessage)
		{
			DbProject projectByCurrentDoc = DbProject.GetProjectByCurrentDoc(this.m_Revit.Application.ActiveUIDocument.Document);
			if (projectByCurrentDoc == null)
			{
				errMessage = "未找到当前工程的结构数据。";
				return false;
			}
			return new ReadStructureInfoFromDbService(projectByCurrentDoc, ref this.m_OldColumnsId, ref this.m_OldBeamsId, ref this.m_OldWallsId, ref this.m_OldFloorsId, ref this.m_BeamStructureData, ref this.m_ColumnStructureData, ref this.m_WallStructureData, ref this.m_FloorStructureData).ReadStructureInfo(ref errMessage);
		}

		private bool ImportBeam(ref MyProgressBar myProgress)
		{
			foreach (BeamInfos beamInfos in this.m_BeamStructureData)
			{
				ElementId oldElementId = beamInfos.OldElementId;
				FamilySymbol beamType = this.GetBeamType(beamInfos);
				this.NoteDownElement(oldElementId, ref this.m_OldBeamsId);
				this.CreateBeamFromStructureInfo(beamInfos, beamType);
				if (!myProgress.ProgressStep(1) && myProgress.IsStoped)
				{
					return false;
				}
			}
			return true;
		}

		private FamilySymbol GetBeamType(BeamInfos beamInfo)
		{
			ElementId oldElementId = beamInfo.OldElementId;
			FamilySymbol result = null;
			if (beamInfo.SectionStyle == PoleSectionStyle.CSS_RECTANG)
			{
				Family family;
				if (null == oldElementId)
				{
					family = (RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, this.m_ImportOption.DefaultRectangeBeamFamilyId) as Family);
				}
				else
				{
					FamilyInstance familyInstance = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, oldElementId) as FamilyInstance;
					if (familyInstance == null)
					{
						family = (RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, this.m_ImportOption.DefaultRectangeBeamFamilyId) as Family);
					}
					else
					{
						family = familyInstance.Symbol.Family;
					}
				}
				result = this.GetRectangleBeamTypeBySize(family, beamInfo.Width, beamInfo.Height);
			}
			return result;
		}

		private FamilySymbol GetRectangleBeamTypeBySize(Family family, double width, double height)
		{
			List<FamilySymbol> symbols = family.GetSymbols();
			FamilySymbol familySymbol = null;
			if (symbols.Count > 0)
			{
				familySymbol = symbols[0];
			}
			string paramName = "";
			string paramName2 = "";
			this.GetRectBeamSectionPropertyName(family, ref paramName, ref paramName2);
			foreach (FamilySymbol familySymbol2 in symbols)
			{
				double val = familySymbol2.GetParameter(paramName).AsDouble();
				double val2 = familySymbol2.GetParameter(paramName2).AsDouble();
				if (Geometry.IsEqual(val, width) && Geometry.IsEqual(val2, height))
				{
					return familySymbol2;
				}
			}
			string text = string.Concat(new string[]
			{
				"HY_",
				family.Name,
				" ",
				Common.FeetToMM(width).ToString("f"),
				" x ",
				Common.FeetToMM(height).ToString("f"),
				" mm"
			});
			FamilySymbol familySymbol3 = familySymbol.Duplicate(text) as FamilySymbol;
			familySymbol3.GetParameter(paramName).Set(width);
			familySymbol3.GetParameter(paramName2).Set(height);
			return familySymbol3;
		}

		private void GetRectBeamSectionPropertyName(Family family, ref string strWName, ref string strHName)
		{
			string name = family.Name;
			foreach (RectSectionMapping rectSectionMapping in this.m_RBeamMapping)
			{
				if (name.CompareTo(rectSectionMapping.FamilyName) == 0)
				{
					strWName = rectSectionMapping.SizeProperties[rectSectionMapping.WidthNameIndex];
					strHName = rectSectionMapping.SizeProperties[rectSectionMapping.HeightNameIndex];
					break;
				}
			}
		}

		private void CreateBeamFromStructureInfo(BeamInfos beamInfo, FamilySymbol symbol)
		{
			XYZ startPoint = beamInfo.StartPoint;
			XYZ endPoint = beamInfo.EndPoint;
			double bulge = beamInfo.Bulge;
			Curve curve;
			if (beamInfo.IsArc)
			{
				XYZ ptCenter = null;
				Geometry.GetCenterWithBulge(startPoint, endPoint, bulge, ref ptCenter);
				XYZ radianPnt = Geometry.CalculatMidPoint(startPoint, endPoint, ptCenter, XYZ.BasisZ);
				curve = this.m_Revit.Application.Application.CreatYJKArc(startPoint, endPoint, radianPnt);
			}
			else
			{
				curve = YJKLineEx.YJKGetBound(startPoint, endPoint);
			}
			double num = 0.0;
			Level nearestLevel = this.GetNearestLevel(startPoint.Z, ref num);
            StructuralType structuralType = (StructuralType)1;
			UnifiedModified.ActivateFamilySymbol(symbol);
			this.m_Revit.Application.ActiveUIDocument.Document.Create.NewFamilyInstance(curve, symbol, nearestLevel, structuralType);
		}

		private bool ImportColumn(ref MyProgressBar myProgress)
		{
			foreach (ColumnInfos columnInfos in this.m_ColumnStructureData)
			{
				ElementId oldElementId = columnInfos.OldElementId;
				FamilySymbol columnType = this.GetColumnType(columnInfos);
				this.NoteDownElement(oldElementId, ref this.m_OldColumnsId);
				this.CreateColumnFromStructureInfo(columnInfos, columnType);
				if (!myProgress.ProgressStep(1) && myProgress.IsStoped)
				{
					return false;
				}
			}
			return true;
		}

		private FamilySymbol GetColumnType(ColumnInfos columnInfo)
		{
			ElementId oldElementId = columnInfo.OldElementId;
			FamilySymbol result = null;
			if (columnInfo.SectionStyle == PoleSectionStyle.CSS_RECTANG)
			{
				Family family;
				if (null == oldElementId)
				{
					family = (RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, this.m_ImportOption.DefaultRectangeColumnFamilyId) as Family);
				}
				else
				{
					FamilyInstance familyInstance = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, oldElementId) as FamilyInstance;
					if (familyInstance == null)
					{
						family = (RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, this.m_ImportOption.DefaultRectangeColumnFamilyId) as Family);
					}
					else
					{
						family = familyInstance.Symbol.Family;
					}
				}
				result = this.GetRectangleColumnTypeBySize(family, columnInfo.H, columnInfo.B);
			}
			else if (columnInfo.SectionStyle == PoleSectionStyle.CSS_CIRCLE)
			{
				Family family2;
				if (null == oldElementId)
				{
					family2 = (RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, this.m_ImportOption.DefaultCircleColumnFamilyId) as Family);
				}
				else
				{
					FamilyInstance familyInstance2 = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, oldElementId) as FamilyInstance;
					if (familyInstance2 == null)
					{
						family2 = (RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, this.m_ImportOption.DefaultCircleColumnFamilyId) as Family);
					}
					else
					{
						family2 = familyInstance2.Symbol.Family;
					}
				}
				result = this.GetCircleColumnTypeBySize(family2, columnInfo.H);
			}
			return result;
		}

		private FamilySymbol GetRectangleColumnTypeBySize(Family family, double h, double b)
		{
			List<FamilySymbol> symbols = family.GetSymbols();
			FamilySymbol familySymbol = null;
			if (symbols.Count > 0)
			{
				familySymbol = symbols[0];
			}
			string paramName = "";
			string paramName2 = "";
			this.GetRectColumnSectionPropertyName(family, ref paramName, ref paramName2);
			foreach (FamilySymbol familySymbol2 in symbols)
			{
				double val = familySymbol2.GetParameter(paramName).AsDouble();
				double val2 = familySymbol2.GetParameter(paramName2).AsDouble();
				if (Geometry.IsEqual(val, h) && Geometry.IsEqual(val2, b))
				{
					return familySymbol2;
				}
			}
			string text = string.Concat(new string[]
			{
				"HY_",
				family.Name,
				" ",
				Common.FeetToMM(h).ToString("f"),
				" x ",
				Common.FeetToMM(b).ToString("f"),
				" mm"
			});
			FamilySymbol familySymbol3 = familySymbol.Duplicate(text) as FamilySymbol;
			familySymbol3.GetParameter(paramName).Set(h);
			familySymbol3.GetParameter(paramName2).Set(b);
			return familySymbol3;
		}

		private void GetRectColumnSectionPropertyName(Family family, ref string strHName, ref string strBName)
		{
			string name = family.Name;
			foreach (RectSectionMapping rectSectionMapping in this.m_RColumnMapping)
			{
				if (name.CompareTo(rectSectionMapping.FamilyName) == 0)
				{
					strBName = rectSectionMapping.SizeProperties[rectSectionMapping.WidthNameIndex];
					strHName = rectSectionMapping.SizeProperties[rectSectionMapping.HeightNameIndex];
					break;
				}
			}
		}

		private FamilySymbol GetCircleColumnTypeBySize(Family family, double diameter)
		{
			List<FamilySymbol> symbols = family.GetSymbols();
			FamilySymbol familySymbol = null;
			if (symbols.Count > 0)
			{
				familySymbol = symbols[0];
			}
			string paramName = "";
			this.GetCircleColumnSectionPropertyName(family, ref paramName);
			foreach (FamilySymbol familySymbol2 in symbols)
			{
				if (Geometry.IsEqual(familySymbol2.GetParameter(paramName).AsDouble(), diameter))
				{
					return familySymbol2;
				}
			}
			string text = string.Concat(new string[]
			{
				"HY_",
				family.Name,
				" ",
				Common.FeetToMM(diameter).ToString("f"),
				" mm"
			});
			FamilySymbol familySymbol3 = familySymbol.Duplicate(text) as FamilySymbol;
			familySymbol3.GetParameter(paramName).Set(diameter);
			return familySymbol3;
		}

		private void GetCircleColumnSectionPropertyName(Family family, ref string strDName)
		{
			string name = family.Name;
			foreach (CircleSectionMapping circleSectionMapping in this.m_CColumnMapping)
			{
				if (name.CompareTo(circleSectionMapping.FamilyName) == 0)
				{
					strDName = circleSectionMapping.SizeProperties[circleSectionMapping.DiameterNameIndex];
					break;
				}
			}
		}

		private void CreateColumnFromStructureInfo(ColumnInfos columnInfo, FamilySymbol symbol)
		{
			XYZ locationPoint = columnInfo.LocationPoint;
            StructuralType structuralType = (StructuralType)3;
			double num = 0.0;
			Level nearestLevel = this.GetNearestLevel(locationPoint.Z, ref num);
			UnifiedModified.ActivateFamilySymbol(symbol);
			FamilyInstance familyInstance = this.m_Revit.Application.ActiveUIDocument.Document.Create.NewFamilyInstance(locationPoint, symbol, nearestLevel, structuralType);
			double num2 = 0.0;
			Level nearestLevel2 = this.GetNearestLevel(locationPoint.Z + columnInfo.Height, ref num2);
			Parameter parameter = familyInstance.GetParameter("底部标高");
			if (parameter != null)
			{
				parameter.Set(nearestLevel.Id);
			}
			Parameter parameter2 = familyInstance.GetParameter("底部偏移");
			if (parameter2 != null)
			{
				parameter2.Set(num);
			}
			Parameter parameter3 = familyInstance.GetParameter("顶部标高");
			if (parameter3 != null)
			{
				parameter3.Set(nearestLevel2.Id);
			}
			Parameter parameter4 = familyInstance.GetParameter("顶部偏移");
			if (parameter4 != null)
			{
				parameter4.Set(num2);
			}
			this.RotateOneColumn(familyInstance, columnInfo.LocationPoint, columnInfo.Rotation);
		}

		protected void RotateOneColumn(FamilyInstance column, XYZ rotatePos, double angle)
		{
			if (column == null)
			{
				return;
			}
			XYZ startPoint = new XYZ(rotatePos.X, rotatePos.Y, 0.0);
			XYZ endPoint = new XYZ(rotatePos.X, rotatePos.Y, 10.0);
			Line line = YJKLineEx.YJKGetBound(startPoint, endPoint);
			ElementTransformUtils.RotateElement(this.m_Revit.Application.ActiveUIDocument.Document, column.Id, line, angle);
		}

		private bool ImportWall(ref MyProgressBar myProgress)
		{
			foreach (WallInfos wallInfos in this.m_WallStructureData)
			{
				ElementId oldElementId = wallInfos.OldElementId;
				WallType wallType = this.GetWallType(wallInfos);
				this.NoteDownElement(oldElementId, ref this.m_OldWallsId);
				this.CreateWallFromStructureInfo(wallInfos, wallType);
				if (!myProgress.ProgressStep(1) && myProgress.IsStoped)
				{
					return false;
				}
			}
			return true;
		}

		private WallType GetWallType(WallInfos wallInfo)
		{
			ElementId oldElementId = wallInfo.OldElementId;
			WallType wallType = null;
			if (null == oldElementId)
			{
				wallType = (RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, this.m_ImportOption.DefaultWallTypeId) as WallType);
			}
			else
			{
				Wall wall = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, oldElementId) as Wall;
				if (wall == null)
				{
					wallType = (RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, this.m_ImportOption.DefaultWallTypeId) as WallType);
				}
				else
				{
					wallType = wall.WallType;
				}
			}
			double width = wallType.Width;
			double wallStructureThickness = this.GetWallStructureThickness(wallType);
			if (Geometry.IsEqual(wallStructureThickness, wallInfo.Thickness))
			{
				return wallType;
			}
			double val = width + (wallInfo.Thickness - wallStructureThickness);
			string text = "HY_" + Common.FeetToMM(val).ToString("f") + "mm";
			foreach (Element element in new FilteredElementCollector(this.m_Revit.Application.ActiveUIDocument.Document).OfClass(typeof(WallType)).ToElements())
			{
				WallType wallType2 = element as WallType;
				if (wallType2 != null && wallType2.Name.CompareTo(text) == 0)
				{
					return wallType2;
				}
			}
			WallType wallType3 = wallType.Duplicate(text) as WallType;
			CompoundStructure compoundStructure = wallType3.GetCompoundStructure();
			IList<CompoundStructureLayer> layers = compoundStructure.GetLayers();
			foreach (CompoundStructureLayer compoundStructureLayer in layers)
			{
				if ((int)compoundStructureLayer.Function == 1)
				{
					compoundStructureLayer.Width = wallInfo.Thickness;
				}
			}
			compoundStructure.SetLayers(layers);
			wallType3.SetCompoundStructure(compoundStructure);
			return wallType3;
		}

		private double GetWallStructureThickness(WallType wallType)
		{
			double result = 0.0;
			foreach (CompoundStructureLayer compoundStructureLayer in wallType.GetCompoundStructure().GetLayers())
			{
				if ((int)compoundStructureLayer.Function == 1)
				{
					result = compoundStructureLayer.Width;
					return result;
				}
			}
			return result;
		}

		private void CreateWallFromStructureInfo(WallInfos wallInfo, WallType wallType)
		{
			XYZ startPoint = wallInfo.StartPoint;
			XYZ endPoint = wallInfo.EndPoint;
			double bulge = wallInfo.Bulge;
			Curve curve;
			if (wallInfo.IsArc)
			{
				XYZ ptCenter = null;
				Geometry.GetCenterWithBulge(startPoint, endPoint, bulge, ref ptCenter);
				XYZ radianPnt = Geometry.CalculatMidPoint(startPoint, endPoint, ptCenter, XYZ.BasisZ);
				curve = this.m_Revit.Application.Application.CreatYJKArc(startPoint, endPoint, radianPnt);
			}
			else
			{
				curve = YJKLineEx.YJKGetBound(startPoint, endPoint);
			}
			double height = wallInfo.Height;
			double num = 0.0;
			Level nearestLevel = this.GetNearestLevel(startPoint.Z, ref num);
			Wall wall = RevitVersionFuncs.NewWall(this.m_Revit.Application.ActiveUIDocument.Document, curve, wallType, nearestLevel, height, 0.0, false, true);
			if (wall != null)
			{
				double num2 = 0.0;
				Level nearestLevel2 = this.GetNearestLevel(startPoint.Z + height, ref num2);
				Parameter parameter = wall.GetParameter("底部限制条件");
				if (parameter != null)
				{
					parameter.Set(nearestLevel.Id);
				}
				Parameter parameter2 = wall.GetParameter("底部偏移");
				if (parameter2 != null)
				{
					parameter2.Set(num);
				}
				Parameter parameter3 = wall.GetParameter("顶部约束");
				if (parameter3 != null)
				{
					parameter3.Set(nearestLevel2.Id);
				}
				Parameter parameter4 = wall.GetParameter("顶部偏移");
				if (parameter4 != null)
				{
					parameter4.Set(num2);
				}
				this.CreateWallHolesFromStructureInfo(wallInfo.Holes, wall);
			}
		}

		private void CreateWallHolesFromStructureInfo(List<WallHoleInfos> wallHolesInfo, Wall wall)
		{
			foreach (WallHoleInfos wallHoleInfos in wallHolesInfo)
			{
				Opening opening = this.m_Revit.Application.ActiveUIDocument.Document.Create.NewOpening(wall, wallHoleInfos.Point1, wallHoleInfos.Point2);
				if (opening != null && null != wallHoleInfos.OldElementId)
				{
					FamilySymbol familySymbol = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, wallHoleInfos.OldElementId) as FamilySymbol;
				}
			}
		}

		private bool ImportFloor(ref MyProgressBar myProgress)
		{
			foreach (FloorInfos floorInfos in this.m_FloorStructureData)
			{
				ElementId oldElementId = floorInfos.OldElementId;
				FloorType floorType = this.GetFloorType(floorInfos);
				this.NoteDownElement(oldElementId, ref this.m_OldFloorsId);
				this.CreateFloorFromStructureInfo(floorInfos, floorType);
				if (!myProgress.ProgressStep(1) && myProgress.IsStoped)
				{
					return false;
				}
			}
			return true;
		}

		private FloorType GetFloorType(FloorInfos floorInfo)
		{
			ElementId oldElementId = floorInfo.OldElementId;
			FloorType floorType = null;
			if (null == oldElementId)
			{
				floorType = (RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, this.m_ImportOption.DefaultFloorTypeId) as FloorType);
			}
			else
			{
				Floor floor = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, oldElementId) as Floor;
				if (floor == null)
				{
					floorType = (RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, this.m_ImportOption.DefaultFloorTypeId) as FloorType);
				}
				else
				{
					floorType = floor.FloorType;
				}
			}
			double num = 0.0;
			double floorStructureThickness = this.GetFloorStructureThickness(floorType, ref num);
			if (Geometry.IsEqual(floorStructureThickness, floorInfo.Thickness))
			{
				return floorType;
			}
			double val = num + (floorInfo.Thickness - floorStructureThickness);
			string text = "HY_" + Common.FeetToMM(val).ToString("f") + "mm";
			foreach (Element element in new FilteredElementCollector(this.m_Revit.Application.ActiveUIDocument.Document).OfClass(typeof(FloorType)).ToElements())
			{
				FloorType floorType2 = element as FloorType;
				if (floorType2 != null && floorType2.Name.CompareTo(text) == 0)
				{
					return floorType2;
				}
			}
			FloorType floorType3 = floorType.Duplicate(text) as FloorType;
			CompoundStructure compoundStructure = floorType3.GetCompoundStructure();
			IList<CompoundStructureLayer> layers = compoundStructure.GetLayers();
			foreach (CompoundStructureLayer compoundStructureLayer in layers)
			{
				if ((int)compoundStructureLayer.Function == 1)
				{
					compoundStructureLayer.Width = floorInfo.Thickness;
				}
			}
			compoundStructure.SetLayers(layers);
			floorType3.SetCompoundStructure(compoundStructure);
			return floorType3;
		}

		private double GetFloorStructureThickness(FloorType floorType, ref double thickness)
		{
			double result = 0.0;
			foreach (CompoundStructureLayer compoundStructureLayer in floorType.GetCompoundStructure().GetLayers())
			{
				if ((int)compoundStructureLayer.Function == 1)
				{
					result = compoundStructureLayer.Width;
				}
				thickness += compoundStructureLayer.Width;
			}
			return result;
		}

		private void CreateFloorFromStructureInfo(FloorInfos floorInfo, FloorType floorType)
		{
			CurveArray curveArray = new CurveArray();
			new SpatialElementBoundaryOptions();
			XYZ xyz = null;
			foreach (EdgeInfos edgeInfos in floorInfo.LoopEdges)
			{
				XYZ startPoint = edgeInfos.StartPoint;
				if (xyz == null)
				{
					xyz = startPoint;
				}
				XYZ endPoint = edgeInfos.EndPoint;
				double bulge = edgeInfos.Bulge;
				Curve curve;
				if (edgeInfos.IsArc)
				{
					XYZ ptCenter = null;
					Geometry.GetCenterWithBulge(startPoint, endPoint, bulge, ref ptCenter);
					XYZ radianPnt = Geometry.CalculatMidPoint(startPoint, endPoint, ptCenter, XYZ.BasisZ);
					curve = this.m_Revit.Application.Application.CreatYJKArc(startPoint, endPoint, radianPnt);
				}
				else
				{
					curve = YJKLineEx.YJKGetBound(startPoint, endPoint);
				}
				curveArray.Append(curve);
			}
			XYZ basisZ = XYZ.BasisZ;
			double num = 0.0;
			Level nearestLevel = this.GetNearestLevel(xyz.Z, ref num);
			Floor floor = this.m_Revit.Application.ActiveUIDocument.Document.Create.NewFloor(curveArray, floorType, nearestLevel, true, basisZ);
			if (floor != null)
			{
				Parameter parameter = floor.GetParameter("标高");
				if (parameter != null)
				{
					parameter.Set(nearestLevel.Id);
				}
				Parameter parameter2 = floor.GetParameter("自标高的高度偏移");
				if (parameter2 != null)
				{
					parameter2.Set(num);
				}
				Common.UpdateModel(this.m_Revit.Application.ActiveUIDocument, false);
				this.CreateFloorHolesFromStructureInfo(floorInfo.Holes, floor);
			}
		}

		private void CreateFloorHolesFromStructureInfo(List<FloorHoleInfos> floorHolesInfo, Floor floor)
		{
			foreach (FloorHoleInfos floorHoleInfos in floorHolesInfo)
			{
				CurveArray curveArray = new CurveArray();
				XYZ xyz = null;
				foreach (EdgeInfos edgeInfos in floorHoleInfos.LoopEdges)
				{
					XYZ startPoint = edgeInfos.StartPoint;
					if (xyz == null)
					{
						xyz = startPoint;
					}
					XYZ endPoint = edgeInfos.EndPoint;
					double bulge = edgeInfos.Bulge;
					Curve curve;
					if (edgeInfos.IsArc)
					{
						XYZ ptCenter = null;
						Geometry.GetCenterWithBulge(startPoint, endPoint, bulge, ref ptCenter);
						XYZ radianPnt = Geometry.CalculatMidPoint(startPoint, endPoint, ptCenter, XYZ.BasisZ);
						curve = this.m_Revit.Application.Application.CreatYJKArc(startPoint, endPoint, radianPnt);
					}
					else
					{
						curve = YJKLineEx.YJKGetBound(startPoint, endPoint);
					}
					curveArray.Append(curve);
				}
				this.m_Revit.Application.ActiveUIDocument.Document.Create.NewOpening(floor, curveArray, true);
			}
		}

		private bool SetSectionSizePropertiesMapping(List<Element> rectBeamSymbolList, List<Element> rectColumnSymbolList, List<Element> circleColumnSymbolList)
		{
			if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_BEAM) == ImportComponentStyleOption.ICS_NULL && (this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_COLUMN) == ImportComponentStyleOption.ICS_NULL)
			{
				return true;
			}
			foreach (Element element in rectBeamSymbolList)
			{
				List<string> list = new List<string>();
				Family family = element as Family;
				List<FamilySymbol> symbols = family.GetSymbols();
				FamilySymbol familySymbol = null;
				if (symbols.Count > 0)
				{
					familySymbol = symbols[0];
				}
				foreach (object obj in familySymbol.Parameters)
				{
					Parameter parameter = (Parameter)obj;
					if ((int)parameter.StorageType == 2 && parameter.AsDouble() > 0.0)
					{
						list.Add(parameter.Definition.Name);
					}
				}
				int widthNameIndex = -1;
				int heightNameIndex = -1;
				if (list.Count == 2)
				{
					widthNameIndex = 0;
					heightNameIndex = 1;
				}
				RectSectionMapping item = new RectSectionMapping(family.Name, list, widthNameIndex, heightNameIndex);
				this.m_RBeamMapping.Add(item);
			}
			foreach (Element element2 in rectColumnSymbolList)
			{
				List<string> list2 = new List<string>();
				Family family2 = element2 as Family;
				List<FamilySymbol> symbols2 = family2.GetSymbols();
				FamilySymbol familySymbol2 = null;
				if (symbols2.Count > 0)
				{
					familySymbol2 = symbols2[0];
				}
				foreach (object obj2 in familySymbol2.Parameters)
				{
					Parameter parameter2 = (Parameter)obj2;
					if ((int)parameter2.StorageType == 2 && parameter2.AsDouble() > 0.0)
					{
						list2.Add(parameter2.Definition.Name);
					}
				}
				int widthNameIndex2 = -1;
				int heightNameIndex2 = -1;
				if (list2.Count == 2)
				{
					widthNameIndex2 = 0;
					heightNameIndex2 = 1;
				}
				RectSectionMapping item2 = new RectSectionMapping(family2.Name, list2, widthNameIndex2, heightNameIndex2);
				this.m_RColumnMapping.Add(item2);
			}
			foreach (Element element3 in circleColumnSymbolList)
			{
				List<string> list3 = new List<string>();
				Family family3 = element3 as Family;
				List<FamilySymbol> symbols3 = family3.GetSymbols();
				FamilySymbol familySymbol3 = null;
				if (symbols3.Count > 0)
				{
					familySymbol3 = symbols3[0];
				}
				foreach (object obj3 in familySymbol3.Parameters)
				{
					Parameter parameter3 = (Parameter)obj3;
					if ((int)parameter3.StorageType == 2 && parameter3.AsDouble() > 0.0)
					{
						list3.Add(parameter3.Definition.Name);
					}
				}
				int diameterNameIndex = -1;
				if (list3.Count == 1)
				{
					diameterNameIndex = 0;
				}
				CircleSectionMapping item3 = new CircleSectionMapping(family3.Name, list3, diameterNameIndex);
				this.m_CColumnMapping.Add(item3);
			}
			if (this.m_RBeamMapping.Count == 0 && this.m_RColumnMapping.Count == 0 && this.m_CColumnMapping.Count == 0)
			{
				return true;
			}
			SectionPropertyMappingForm sectionPropertyMappingForm = new SectionPropertyMappingForm(this.m_RBeamMapping, this.m_RColumnMapping, this.m_CColumnMapping);
			if (sectionPropertyMappingForm.ShowDialog() != DialogResult.OK)
			{
				return false;
			}
			this.m_RBeamMapping = sectionPropertyMappingForm.RBeamMapping;
			this.m_RColumnMapping = sectionPropertyMappingForm.RColumnMapping;
			this.m_CColumnMapping = sectionPropertyMappingForm.CColumnMapping;
			return true;
		}

		private Level GetNearestLevel(double elevation, ref double offset)
		{
			Level result = null;
			double num = double.MaxValue;
			foreach (Level level in this.m_AllLevels)
			{
				double num2 = Math.Abs(elevation - level.Elevation);
				if (num2 < num)
				{
					result = level;
					num = num2;
					offset = elevation - level.Elevation;
				}
			}
			return result;
		}

		private void NoteDownElement(ElementId oldId, ref List<ElementId> oldElementsId)
		{
			if (oldElementsId.FindIndex((ElementId s) => s == oldId) >= 0)
			{
				return;
			}
			oldElementsId.Add(oldId);
		}

		private void EreaseOldElements()
		{
			if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_BEAM) != ImportComponentStyleOption.ICS_NULL)
			{
				foreach (ElementId elementId in this.m_OldBeamsId)
				{
					this.m_Revit.Application.ActiveUIDocument.Document.Delete(elementId);
				}
			}
			if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_COLUMN) != ImportComponentStyleOption.ICS_NULL)
			{
				foreach (ElementId elementId2 in this.m_OldColumnsId)
				{
					this.m_Revit.Application.ActiveUIDocument.Document.Delete(elementId2);
				}
			}
			if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_WALL) != ImportComponentStyleOption.ICS_NULL)
			{
				foreach (ElementId elementId3 in this.m_OldWallsId)
				{
					this.m_Revit.Application.ActiveUIDocument.Document.Delete(elementId3);
				}
			}
			if ((this.m_ImportOption.ImportComponentStyle & ImportComponentStyleOption.ICS_FLOOR) != ImportComponentStyleOption.ICS_NULL)
			{
				foreach (ElementId elementId4 in this.m_OldFloorsId)
				{
					this.m_Revit.Application.ActiveUIDocument.Document.Delete(elementId4);
				}
			}
		}

		private bool IsImportedWithBeam()
		{
			foreach (BeamInfos beamInfos in this.m_BeamStructureData)
			{
				ElementId oldElementId = beamInfos.OldElementId;
				if (!(null == oldElementId))
				{
					FamilyInstance familyInstance = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, oldElementId) as FamilyInstance;
					if (familyInstance != null)
					{
						return false;
					}
				}
			}
			return this.IsDeletedOldComponent(this.m_OldBeamsId);
		}

		private bool IsImportedWithColumn()
		{
			foreach (ColumnInfos columnInfos in this.m_ColumnStructureData)
			{
				ElementId oldElementId = columnInfos.OldElementId;
				if (!(null == oldElementId))
				{
					FamilyInstance familyInstance = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, oldElementId) as FamilyInstance;
					if (familyInstance != null)
					{
						return false;
					}
				}
			}
			return this.IsDeletedOldComponent(this.m_OldColumnsId);
		}

		private bool IsImportedWithWall()
		{
			foreach (WallInfos wallInfos in this.m_WallStructureData)
			{
				ElementId oldElementId = wallInfos.OldElementId;
				if (!(null == oldElementId))
				{
					Wall wall = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, oldElementId) as Wall;
					if (wall != null)
					{
						return false;
					}
				}
			}
			return this.IsDeletedOldComponent(this.m_OldWallsId);
		}

		private bool IsImportedWithFloor()
		{
			foreach (FloorInfos floorInfos in this.m_FloorStructureData)
			{
				ElementId oldElementId = floorInfos.OldElementId;
				if (!(null == oldElementId))
				{
					Floor floor = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, oldElementId) as Floor;
					if (floor != null)
					{
						return false;
					}
				}
			}
			return this.IsDeletedOldComponent(this.m_OldFloorsId);
		}

		private bool IsDeletedOldComponent(List<ElementId> oldElementsId)
		{
			if (oldElementsId.Count == 0)
			{
				return false;
			}
			foreach (ElementId id in oldElementsId)
			{
				Element element = RevitVersionFuncs.GetElement(this.m_Revit.Application.ActiveUIDocument.Document, id);
				if (element != null)
				{
					return false;
				}
			}
			return true;
		}

		private ExternalCommandData m_Revit;

		private ImportOptions m_ImportOption;

		private List<Level> m_AllLevels = new List<Level>();

		private List<ElementId> m_OldColumnsId = new List<ElementId>();

		private List<ElementId> m_OldBeamsId = new List<ElementId>();

		private List<ElementId> m_OldWallsId = new List<ElementId>();

		private List<ElementId> m_OldFloorsId = new List<ElementId>();

		private List<BeamInfos> m_BeamStructureData = new List<BeamInfos>();

		private List<ColumnInfos> m_ColumnStructureData = new List<ColumnInfos>();

		private List<WallInfos> m_WallStructureData = new List<WallInfos>();

		private List<FloorInfos> m_FloorStructureData = new List<FloorInfos>();

		private List<RectSectionMapping> m_RBeamMapping = new List<RectSectionMapping>();

		private List<RectSectionMapping> m_RColumnMapping = new List<RectSectionMapping>();

		private List<CircleSectionMapping> m_CColumnMapping = new List<CircleSectionMapping>();
	}
}
